package sseGameApps.controller.mdkbr.main;

import java.util.HashMap;
import java.util.Map;

import org.slim3.controller.Navigation;

import sseGameApps.controller.JsonController;
import sseGameApps.model.mdkbr.MdDecoration;
import sseGameApps.model.mdkbr.MdKbrUser;
import sseGameApps.service.mdkbr.MdDecorationService;
import sseGameApps.service.mdkbr.MdKbrUserService;

public class MdRecordStartController extends JsonController {

    private MdKbrUserService serviceMdKbrUser = new MdKbrUserService();
    private MdDecorationService serviceMdDecoration = new MdDecorationService();

    @Override
    public Navigation run() throws Exception {

        MdKbrUser mdKbrUserP =
            serviceMdKbrUser.getMdKbrUser(asString("userId"));

        Integer starCnt = 0;
        Map<String, String> data = new HashMap<String, String>();

        data.put("userId", asString("userId"));
        data.put("idCanvas", asString("idCanvas"));

        if (mdKbrUserP == null) {
            data.put("playerName", asString("userId"));
            data.put("playerSchool", "001");
            data.put("playerSex", "1");
            data.put("playerType", "KI");
            data.put("userExp", "0");
            data.put("userLevel", "1");
            data.put("playerCG", "m_001R.png");
            data.put("battleCount", "0");
            data.put("winCount", "0");
            data.put("loseCount", "0");
            data.put("playerStr", "0");
        } else {
            data.put("playerName", mdKbrUserP.getPlayerName());
            data.put("playerSchool", mdKbrUserP.getPlayerSchool());
            data.put("playerSex", mdKbrUserP.getPlayerSex());
            data.put("playerType", mdKbrUserP.getPlayerType());
            data.put("userExp", mdKbrUserP.getUserExp().toString());
            data.put("userLevel", mdKbrUserP.getUserLevel().toString());
            data.put("playerCG", mdKbrUserP.getPlayerCGType());
            data.put("battleCount", mdKbrUserP.getBattleCount().toString());
            data.put("winCount", mdKbrUserP.getWinCount().toString());
            data.put("loseCount", mdKbrUserP.getLoseCount().toString());

            MdDecoration mdDecoration = serviceMdDecoration.getMdDecoration(asString("userId"));
            if (mdDecoration != null) {
                if(mdDecoration.isEventComplete1()){
                    starCnt++;
                }
                if(mdDecoration.isEventComplete2()){
                    starCnt++;
                }
                if(mdDecoration.isEventComplete3()){
                    starCnt++;
                }
            }
            data.put("playerStr", starCnt.toString());
        }

        this.toJson(data);

        return null;

    }
}
